package com.wgts.wgts.mvp.view.activity.shopkeeper;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.netmodle.resp.SearchShopResultEntity;
import com.wgts.wgts.tools.AppInfor;
import com.wgts.wgts.tools.MoHuGlide;

import butterknife.BindView;
import butterknife.ButterKnife;

public class VipGoodsAdapter extends RecyclerView.Adapter<VipGoodsAdapter.VIPgoodsViewHolder> {


    private Context context;

    private SearchShopResultEntity searchShopResultEntity;

    private OnClickListener onClickListener;



    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public VipGoodsAdapter(Context context, SearchShopResultEntity searchShopResultEntity) {
        this.context = context;
        this.searchShopResultEntity = searchShopResultEntity;
    }

    @NonNull
    @Override
    public VIPgoodsViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new VIPgoodsViewHolder(LayoutInflater.from(context).inflate(R.layout.keep_shop_goods_view_holder, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull VIPgoodsViewHolder viPgoodsViewHolder, final int i) {
        SearchShopResultEntity.ShopList shopList = searchShopResultEntity.list.get(i);
        MoHuGlide.getInstance().glideImgsFormList(viPgoodsViewHolder.imgProduct, shopList.productSmallImage, context);
        viPgoodsViewHolder.tvProduct.setText(shopList.productName);
        viPgoodsViewHolder.tvProductPrice.setText("￥" + shopList.retailPrice);
        viPgoodsViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onClickListener != null){
                    onClickListener.onClick(v, i);
                }
            }
        });

        if(AppInfor.getInstance().getUserState() > 1){
            viPgoodsViewHolder.tvState.setText("立即分享");
        }else{
            viPgoodsViewHolder.tvState.setText("立即购买");
        }


    }

    @Override
    public int getItemCount() {
        return searchShopResultEntity.list.size();
    }

    public class VIPgoodsViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.img_product)
        ImageView imgProduct;
        @BindView(R.id.tv_product)
        TextView tvProduct;
        @BindView(R.id.tv_product_price)
        TextView tvProductPrice;
        @BindView(R.id.tv_state)
        TextView tvState;
        @BindView(R.id.linear_buy)
        LinearLayout linearBuy;

        public View itemView;

        public VIPgoodsViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            this.itemView = itemView;
        }
    }

    public interface OnClickListener{
        void onClick(View view, int i);
    }
}
